package com.shanzhu.beadhouse.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shanzhu.beadhouse.entity.po.ServicePurchase;
import com.shanzhu.beadhouse.entity.query.GetPurchaseByIdQuery;
import com.shanzhu.beadhouse.entity.query.PagePurchaseByKeysQuery;
import com.shanzhu.beadhouse.entity.vo.GetPurchaseByIdVo;
import com.shanzhu.beadhouse.entity.vo.PageServiceLogVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ServicePurchaseMapper extends BaseMapper<ServicePurchase> {

    List<PageServiceLogVo> listPurchaseLogByKey(PagePurchaseByKeysQuery query);

    GetPurchaseByIdVo getPurchase(GetPurchaseByIdQuery query);

    void batchUpsert(List<Long> serviceIds,Long eid);

    @Select("select * \n" +
            "from service_purchases sp\n" +
            "where sp.eid=#{eid}\n" +
            "AND sp.sid=#{sid}\n" +
            "AND sp.del_flag='N'\n" +
            "AND sp.overdue>NOW() " +
            "ORDER BY sp.overdue ASC")
    List<ServicePurchase> getUsablePurchaseList(Long sid,Long eid);

}
